﻿using SD.OpcProxy.Domain.Entities;
using SD.OpcProxy.IAppService.DTOs.Outputs;
using SD.Toolkits.Mapper;
using System;
using System.Collections.Generic;

namespace SD.OpcProxy.AppService.Maps
{
    /// <summary>
    /// 自动化相关映射工具类
    /// </summary>
    public static class OpcProxyMap
    {
        #region # OPC服务器映射 —— static OpcServerInfo ToDTO(this OpcServer server)
        /// <summary>
        /// OPC服务器映射
        /// </summary>
        public static OpcServerInfo ToDTO(this OpcServer server)
        {
            OpcServerInfo serverInfo = server.Map<OpcServer, OpcServerInfo>();

            return serverInfo;
        }
        #endregion

        #region # 变量映射 —— static VariableInfo ToDTO(this Variable variable...
        /// <summary>
        /// 变量映射
        /// </summary>
        public static VariableInfo ToDTO(this Variable variable, IDictionary<Guid, OpcServerInfo> opcServerInfos)
        {
            VariableInfo variableInfo = variable.Map<Variable, VariableInfo>();
            variableInfo.OpcServerInfo = opcServerInfos?[variable.OpcServerId];

            return variableInfo;
        }
        #endregion

        #region # 变量历史映射 —— static VariableHistoryInfo ToDTO(this VariableHistory record)
        /// <summary>
        /// 变量历史映射
        /// </summary>
        public static VariableHistoryInfo ToDTO(this VariableHistory record)
        {
            VariableHistoryInfo recordInfo = record.Map<VariableHistory, VariableHistoryInfo>();

            return recordInfo;
        }
        #endregion
    }
}
